home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / gfx / fract / FlashMandel.lha / FlashMandel / Sources / Modules / Gfx.c < prev    next >
C/C++ Source or Header  |  1999-01-22  |  7KB  |  283 lines

  1. /**********************************************************************************************************
  2. **
  3. **  Coded by Dino Papararo     16-Jan-1999
  4. **
  5. **  FUNCTION
  6. **
  7. **    Fade -- perform screen color fading from/to black.
  8. **
  9. **  SYNOPSIS
  10. **
  11. **    BOOL Fade (struct Window *Win,ULONG *PaletteSrc,ULONG MaxStep,ULONG TimeDelay,BOOL ToBlack)
  12. **
  13. **  DESCRIPTION
  14. **
  15. **    According with ToBlack value screen will fade from black to PaletteSrc or from PaletteSrc to black.
  16. **
  17. **    MaxStep is number of times colors will be decreased/increased from/to black.
  18. **
  19. **    TimeDelay is the wait time between two palette changes, is necessary for multitasking and faster cpu.
  20. **
  21. **  RETURN
  22. **
  23. **    FALSE if screen proprieties not available or Depth < 2 or MaxStep < 2, TRUE color cycling performed.
  24. **
  25. ***********************************************************************************************************
  26. **
  27. **  Coded by Claudio Pucci & Dino Papararo     26-Oct-1997
  28. **
  29. **  FUNCTION
  30. **
  31. **    Cycle -- perform screen color cycling.
  32. **
  33. **  SYNOPSIS
  34. **
  35. **    BOOL Cycle (struct Window *Win,ULONG TimeDelay,BOOL Left)
  36. **
  37. **  DESCRIPTION
  38. **
  39. **    Function uses a double sized table to manage color cycling.
  40. **
  41. **    So we do not need to save and shift all colors for every cycle,
  42. **
  43. **    but only save and set correct first and last values !
  44. **
  45. **    This function do not load the first four color registers reserved for GUI pens.
  46. **
  47. **  RETURN
  48. **
  49. **    FALSE if screen proprieties not available or Depth < 2, TRUE color cycling performed.
  50. **
  51. **********************************************************************************************************/
  52.  
  53. #define __USE_SYSBASE
  54.  
  55. #include <exec/types.h>
  56. #include <proto/dos.h>
  57. #include <proto/intuition.h>
  58. #include <proto/graphics.h>
  59. #include <proto/gadtools.h>
  60. #include <intuition/intuition.h>
  61. #include <graphics/gfxbase.h>
  62.  
  63. #define RAW_ESC 0x45
  64.  
  65. #define RESERVED_PENS 4L
  66.  
  67. #define BLACK 0L
  68.  
  69. BOOL Fade (struct Window *,ULONG *,ULONG,ULONG,BOOL);
  70. BOOL Cycle (struct Window *,ULONG,BOOL);
  71.  
  72. BOOL Fade (struct Window *Win,ULONG *PaletteSrc,ULONG MaxStep,ULONG TimeDelay,BOOL ToBlack)
  73. {
  74. DisplayInfoHandle DHandle;
  75.  
  76. struct DisplayInfo DInfo;
  77.  
  78. static ULONG PaletteTmp [3L * 252L + 2L];
  79.  
  80. LONG Var,Step;
  81.  
  82. ULONG Range,ModeID;
  83.  
  84. BOOL AllBlack;
  85.  
  86.   if ((Win->RPort->BitMap->Depth < 2L) || (MaxStep < 2L)) return FALSE;
  87.  
  88.   ModeID = GetVPModeID (ViewPortAddress (Win));
  89.  
  90.   DHandle = FindDisplayInfo (ModeID);
  91.  
  92.   if (GetDisplayInfoData (DHandle,(UBYTE *) &DInfo,sizeof (struct DisplayInfo),DTAG_DISP,ModeID))
  93.   {
  94.      if (DInfo.PropertyFlags & DIPF_IS_EXTRAHALFBRITE) Range = 32L - 4L;
  95.  
  96.      else Range = (1L << Win->RPort->BitMap->Depth) - 4L;
  97.  
  98.      PaletteTmp [0L] = (Range << 16L) + 4L;
  99.  
  100.      GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,Range,&PaletteTmp [1L]);
  101.  
  102.      PaletteTmp [3L * Range + 1L] = NULL;
  103.  
  104.      if (ToBlack)
  105.      {
  106.         for (Step = 0L; Step <= MaxStep; Step++)
  107.         {
  108.             AllBlack = TRUE;
  109.  
  110.             for (Var = 1; Var <= 3L * Range; Var++)
  111.             {
  112.                 if (PaletteTmp [Var])
  113.                 {
  114.                    PaletteTmp [Var] = (((PaletteSrc [Var + (3 * RESERVED_PENS)] >> 24L) * (MaxStep - Step)) / MaxStep) << 24L;
  115.  
  116.                    AllBlack = FALSE;
  117.                 }
  118.             }
  119.  
  120.             if (AllBlack) break;
  121.  
  122.             WaitTOF ();
  123.  
  124.             LoadRGB32 (ViewPortAddress (Win),PaletteTmp);
  125.  
  126.             Delay (TimeDelay);
  127.         }
  128.      }
  129.  
  130.      else
  131.      {
  132.         for (Step = MaxStep; Step >= 0L; Step--)
  133.         {
  134.             for (Var = 1; Var <= 3L * Range; Var++)
  135.  
  136.                 PaletteTmp [Var] = (((PaletteSrc [Var + (3 * RESERVED_PENS)] >> 24L) * (MaxStep - Step)) / MaxStep) << 24L;
  137.  
  138.             WaitTOF ();
  139.  
  140.             LoadRGB32 (ViewPortAddress (Win),PaletteTmp);
  141.  
  142.             Delay (TimeDelay);
  143.         }
  144.  
  145.         LoadRGB32 (ViewPortAddress (Win),PaletteSrc);
  146.      }
  147.  
  148.      return TRUE;
  149.   }
  150.  
  151.   return FALSE;
  152. }
  153.  
  154. BOOL Cycle (struct Window *Win,ULONG TimeDelay,BOOL Left)
  155. {
  156. DisplayInfoHandle DHandle;
  157.  
  158. struct DisplayInfo DInfo;
  159.  
  160. struct IntuiMessage *Message;
  161.  
  162. static ULONG Palette_Tmp [2L * 3L * 252L + 2L];
  163.  
  164. BOOL Loop = TRUE;
  165.  
  166. UWORD MyCode = 0;
  167.  
  168. ULONG MyClass = NULL,Counter = NULL,OldBlue,OldRed,Tmp_1,Tmp_2,HalfRange;
  169.  
  170. ULONG ModeID,Range;
  171.  
  172.   if (Win->RPort->BitMap->Depth < 2L) return FALSE;
  173.  
  174.   ModeID = GetVPModeID (ViewPortAddress (Win));
  175.  
  176.   DHandle = FindDisplayInfo (ModeID);
  177.  
  178.   if (GetDisplayInfoData (DHandle,(UBYTE *) &DInfo,sizeof (struct DisplayInfo),DTAG_DISP,ModeID))
  179.   {
  180.      if (DInfo.PropertyFlags & DIPF_IS_EXTRAHALFBRITE)
  181.      {
  182.         Range = 64L - 8L;
  183.  
  184.         HalfRange = Range >> 1L;
  185.  
  186.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [1L]);
  187.  
  188.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * HalfRange + 1L]);
  189.  
  190.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * (2L * HalfRange) + 1L]);
  191.  
  192.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * (3L * HalfRange) + 1L]);
  193.  
  194.         Palette_Tmp [3L * 2L * (4L * HalfRange) + 1L] = NULL;
  195.      }
  196.  
  197.      else
  198.      {
  199.         Range = (1L << Win->RPort->BitMap->Depth) - 4L;
  200.  
  201.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,Range,&Palette_Tmp [1L]);
  202.  
  203.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,Range,&Palette_Tmp [3L * Range + 1L]);
  204.  
  205.         Palette_Tmp [2L * 3L * Range + 1L] = NULL;
  206.      }
  207.  
  208.      Palette_Tmp [0L] = (Range << 16L) + 4L;
  209.  
  210.      if (! Left) Counter = Range + 1L;
  211.  
  212.      while (Loop)
  213.      {
  214.            if (Win->UserPort->mp_SigBit)
  215.            {
  216.               if (Message = (struct IntuiMessage *) GT_GetIMsg (Win->UserPort))
  217.               {
  218.                  MyClass = Message->Class;
  219.  
  220.                  MyCode  = Message->Code;
  221.  
  222.                  GT_ReplyIMsg ((struct IntuiMessage *) Message);
  223.               }
  224.  
  225.               switch (MyClass)
  226.               {
  227.                  case IDCMP_MOUSEBUTTONS:  if (MyCode == SELECTDOWN) Loop = FALSE;
  228.  
  229.                                            break;
  230.  
  231.                  case IDCMP_MENUPICK    :  Loop = FALSE;
  232.  
  233.                                            break;
  234.  
  235.                  case IDCMP_RAWKEY      :  if (MyCode == RAW_ESC) Loop = FALSE;
  236.  
  237.                                            break;
  238.               }
  239.            }
  240.  
  241.            if (Left)
  242.            {
  243.               Counter++;
  244.  
  245.               if (Counter > Range) Counter = 1L;
  246.            }
  247.  
  248.            else
  249.            {
  250.               Counter--;
  251.  
  252.               if (Counter < 1L) Counter = Range;
  253.            }
  254.  
  255.            Tmp_1 = 3L * Counter;
  256.  
  257.            Tmp_2 = 3L * (Counter + Range) + 1L;
  258.  
  259.            OldBlue = Palette_Tmp [Tmp_1];
  260.  
  261.            OldRed  = Palette_Tmp [Tmp_2];
  262.  
  263.            Palette_Tmp [Tmp_1] = (Range << 16L) + 4L;
  264.  
  265.            Palette_Tmp [Tmp_2] = NULL;
  266.  
  267.            WaitTOF ();
  268.  
  269.            LoadRGB32 (ViewPortAddress (Win),&Palette_Tmp [3L * Counter]);
  270.  
  271.            Delay (TimeDelay);
  272.  
  273.            Palette_Tmp [Tmp_1] = OldBlue;
  274.  
  275.            Palette_Tmp [Tmp_2] = OldRed;
  276.      }
  277.  
  278.      return TRUE;
  279.   }
  280.  
  281.   return FALSE;
  282. }
  283.